﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ViewRidgeAssistant
{
    public partial class form_search : Form
    {
        private form_customer _parent_customer;
        private form_transaction _parent_transaction;
        //private form_artist _parent_artist;
        private data_source _data_module;
        private string _id;
        //private string _state;
        public class_customer _customer;

        //Форма в режиме добавления интересов клиента
        public form_search(form_customer parent, data_source data_module, int cust_id)
        {
            InitializeComponent();
            this._parent_customer = parent;
            this._data_module = data_module;
            this._id = cust_id.ToString();
            //this.tbp_artists.Enabled = false;
            //this._state = "ARTIST";
            this.num_start_bd_date.Value = 1900;
            this.num_end_bd_date.Value = 1900;
            this.num_start_dd_date.Value = 1900;
            this.num_end_dd_date.Value = 1900;
            this.b_add_int.Enabled = false;


        }

        public form_search(form_transaction parent, data_source data_module, class_customer customer)
        {
            InitializeComponent();
            this._parent_transaction = parent;
            this._data_module = data_module;
            this._customer = customer;
            this.tb_elements.SelectedIndex = 1;

            this.tbp_artists.Enabled = false;

        }

        private void b_find_Click(object sender, EventArgs e)
        {
            DataTable table;
            table = this._data_module.get_artists_by_param(this.cb_name.Checked,
                                                   this.cb_nat.Checked,
                                                   this.cb_bd_date.Checked,
                                                   this.cb_dd_date.Checked,
                                                   this.t_name.Text,
                                                   this.t_nat.Text,
                                                   Convert.ToInt32(this.num_start_bd_date.Value),
                                                   Convert.ToInt32(this.num_end_bd_date.Value),
                                                   Convert.ToInt32(this.num_start_dd_date.Value),
                                                   Convert.ToInt32(this.num_end_dd_date.Value));
            gw.DataSource = table;
            gw.Update();
            this.b_add_int.Enabled = true;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this._parent_customer.Enabled = true;
            this.Dispose();
        }

        private void b_add_int_Click(object sender, EventArgs e)
        {
            bool in_list = false;
            in_list = this._data_module.check_interest(Convert.ToInt32(this._id), Convert.ToInt32(gw.Rows[gw.CurrentRow.Index].Cells[0].Value.ToString()));
            if (!(in_list)) 
            {
                //MessageBox.Show("добавление");
                this._data_module.add_interest(Convert.ToInt32(this._id), Convert.ToInt32(gw.Rows[gw.CurrentRow.Index].Cells[0].Value.ToString()));
            }
            else
            {
                this._data_module.del_interest(Convert.ToInt32(this._id), Convert.ToInt32(gw.Rows[gw.CurrentRow.Index].Cells[0].Value.ToString()));
            }
            
            this._parent_customer.update_interests();
        }

        private void ClosedSearch(object sender, FormClosedEventArgs e)
        {
            //this._parent_customer.Enabled = true;
            //this.Dispose();
        }

        private void b_search_Click(object sender, EventArgs e)
        {
            
        }

        private void b_use_Click(object sender, EventArgs e)
        {
            //this._customer = this._data_module.get_customer(Convert.ToInt32(gw.Rows[gw.CurrentRow.Index].Cells[0].Value.ToString()));
            this._customer.customer_id = gw.Rows[gw.CurrentRow.Index].Cells[0].Value.ToString();
            this.Dispose();
        }

        private void enable_cust_find(object sender, EventArgs e)
        {
            
        }

        private void form_search_Load(object sender, EventArgs e)
        {

        }

        
    }
}
